/***************************************************************************
 *   Copyright (C) 2007 by Alexandre Masselot,,,   *
 *   alex@alex-laptop   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Library General Public License as       *
 *   published by the Free Software Foundation; either version 2 of the    *
 *   License, or (at your option) any later version.                       *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU Library General Public     *
 *   License along with this program; if not, write to the                 *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#include "deltamassbuilder.h"

namespace bol {
    DeltaMass* DeltaMassBuilder::deltamassInstance(const string& s)const{
        //this method is called only rarely, so let's instance locall those object...
        boost::regex re;
        boost::cmatch matches;

        re.assign("^\\s*([\\d\\.]+)\\s*da\\s*$", boost::regex_constants::icase|boost::regex_constants::perl);
        if(boost::regex_match(s.c_str(), matches, re)){
           DeltaMassDA *delta=new DeltaMassDA();
           string tmp(matches[1]);
           double d=boost::lexical_cast<double>(tmp);
           delta->setTol(d);
           return delta;
        }
        
        re.assign("^\\s*([\\d\\.]+)\\s*ppm\\s*$", boost::regex_constants::icase|boost::regex_constants::perl);
        if(boost::regex_match(s.c_str(), matches, re)){
           DeltaMassPPM *delta=new DeltaMassPPM();
           string tmp(matches[1]);
           double d=boost::lexical_cast<double>(tmp);
           delta->setTol(d);
           return delta;
        }
        
        // HACK if there's nothing that match, what should I return ?
        return NULL;
        // TODO do a proper return
    }

}
